import 'package:dio/dio.dart';

class MyDio {
  static late Dio _dio = _init();

  static Dio get dio  => _dio;

  static Dio _init() {
    var d = Dio();
    d.interceptors.add(InterceptorsWrapper(
      onRequest: (options, handler) {
        print('发出请求：=>${options.headers.toString()}');
        handler.next(options);
      },
      onResponse: (response, handler) {
        print('获得响应 =>${response.data}');
        handler.next(response);
      },
      onError: (err, handler) {
        print('请求出错=> ${err.toString()}');
        handler.next(err);
      },
    ));
    d.options = BaseOptions(
      baseUrl: 'http://10.203.71.19:8080/',
      connectTimeout: 5000,
      sendTimeout: 5000,
      receiveTimeout: 5000,
      headers: {'token': '55454482451'},
      contentType: Headers.jsonContentType,
      responseType: ResponseType.json,
    );
    return d;
  }
}
